package app.server.project.main.service.db.dao.cfg;

import app.server.project.main.service.db.entity.cfg.RankRewardCfgEntity;
import app.server.project.main.service.db.mapper.cfg.RankRewardCfgMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RankRewardCfgDao extends ServiceImpl<RankRewardCfgMapper, RankRewardCfgEntity> {

    private List<RankRewardCfgEntity> cfgEntityList = null;


    public List<RankRewardCfgEntity> getAll() {
        return cfgEntityList;
    }

    @PostConstruct
    public void init() {
        this.flush();
    }

    public void flush() {
        this.cfgEntityList = this.list(Wrappers.<RankRewardCfgEntity>lambdaQuery().orderByAsc(RankRewardCfgEntity::getId));
    }

    public RankRewardCfgEntity getByRaceId(int typeId) {
        return this.cfgEntityList.stream().filter(v -> v.getId() == typeId).findFirst().get();
    }
}
